package com.mgq.design.chainofresponsibility.c2;

/**
 * <b>功能：</b>抽象类,标准的责任链模式<br>
 * <b>Copyright TCSL</b>
 * <li>版本&nbsp;&nbsp;&nbsp;&nbsp;修改日期&nbsp;&nbsp;&nbsp;&nbsp;部　　门&nbsp;&nbsp;&nbsp;&nbsp;作　者&nbsp;&nbsp;&nbsp;&nbsp;变更内容</li><hr>
 * <li>v1.0&nbsp;&nbsp;&nbsp;&nbsp;20220425&nbsp;&nbsp;营业后台&nbsp;&nbsp;&nbsp;&nbsp;马广奇&nbsp;&nbsp;&nbsp;&nbsp;创建类</li>
 * <br><br>
 *
 * @author 马广奇
 * @version 2022-04-25 17:37
 */
public abstract class ProcessingObject<T> {

    //successor 接班人
    protected ProcessingObject<T> successor;

    protected abstract T handlerWork(T t);

    public void setSuccessor(ProcessingObject<T> successor) {
        this.successor = successor;
    }

    public T handler(T input) {
        T t = handlerWork(input);
        if (this.successor != null) {
            //继续处理
            return successor.handler(t);
        }
        return t;
    }
}
